﻿package Gameplay.Labels
{	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;

	public class TrackNameLabel extends MovieClip
	{		
		private var FText:TextField;
		private var FWidth:Number;
		private var FStep:int;
		private var FMoving:Boolean;
		
		public function TrackNameLabel() 
		{
			FText = getChildByName('Text') as TextField;
			FWidth = 154;	
			FStep = -1;
		}
		
		function OnEnterFrame(e:Event):void
		{						
			if (FStep == -1)
			{
				if(FText.x > (FWidth - FText.width))
				{				
					FText.x--;
				}
				else
				{				
					FStep = 1;				
				}
			}
			else
			{
				if(FText.x < 10)
				{				
					FText.x++;
				}
				else
				{				
					FStep = -1;				
				}		
			}
		}
		
		public function set text(AText:String):void
		{
			FText.text = '';
			FText.width = 0;
			
			FText.text = AText;
			FText.width = FText.textWidth + 10;
			if(FText.width > FWidth)
				addEventListener(Event.ENTER_FRAME, OnEnterFrame);
			else
				removeEventListener(Event.ENTER_FRAME, OnEnterFrame);
		}		
	}	
}
